package com.ruoyi.Evaluation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.Evaluation.domain.Evaluation;
import com.ruoyi.Evaluation.service.IEvaluationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评分信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/Evaluation/evaluation")
public class EvaluationController extends BaseController
{
    @Autowired
    private IEvaluationService evaluationService;

    /**
     * 查询评分信息列表
     */
    @PreAuthorize("@ss.hasPermi('Evaluation:evaluation:list')")
    @GetMapping("/list")
    public TableDataInfo list(Evaluation evaluation)
    {
        startPage();
        evaluation.setExpertId(getUserId());
        List<Evaluation> list = evaluationService.selectEvaluationList(evaluation);
        return getDataTable(list);
    }

    /**
     * 导出评分信息列表
     */
    @PreAuthorize("@ss.hasPermi('Evaluation:evaluation:export')")
    @Log(title = "评分信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Evaluation evaluation)
    {
        List<Evaluation> list = evaluationService.selectEvaluationList(evaluation);
        ExcelUtil<Evaluation> util = new ExcelUtil<Evaluation>(Evaluation.class);
        util.exportExcel(response, list, "评分信息数据");
    }

    /**
     * 获取评分信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('Evaluation:evaluation:query')")
    @GetMapping(value = "/{resultId}")
    public AjaxResult getInfo(@PathVariable("resultId") Long resultId)
    {
        return success(evaluationService.selectEvaluationByResultId(resultId));
    }

    /**
     * 新增评分信息
     */
    @PreAuthorize("@ss.hasPermi('Evaluation:evaluation:add')")
    @Log(title = "评分信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Evaluation evaluation)
    {
        evaluation.setExpertId(getLoginUser().getUserId());
        return toAjax(evaluationService.insertEvaluation(evaluation));
    }

    /**
     * 修改评分信息
     */
    @PreAuthorize("@ss.hasPermi('Evaluation:evaluation:edit')")
    @Log(title = "评分信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Evaluation evaluation)
    {
        return toAjax(evaluationService.updateEvaluation(evaluation));
    }

    /**
     * 删除评分信息
     */
    @PreAuthorize("@ss.hasPermi('Evaluation:evaluation:remove')")
    @Log(title = "评分信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{resultIds}")
    public AjaxResult remove(@PathVariable Long[] resultIds)
    {
        return toAjax(evaluationService.deleteEvaluationByResultIds(resultIds));
    }
}
